﻿<!DOCTYPE html>
<html>
<head>
  <title></title>
  <link href="/style/rightdirectory.css" rel="stylesheet"/>
  <script src="/script/config.js"></script>
</head>

<body>
<h5>产品属性值</h5>
<div class="form-body">
  <div class="form-horizontal  hide" id="form">

  </div>
</div>
</body>
</html>
<script type="text/html" id="tp-form">
    
    <div class="form-group">
        <label class="col-sm-2">产品属性值</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" data-form="AttrValue" placeholder="产品属性值" value="{{AttrValue}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2">属性key名称</label>
        <div class="col-md-6 col-sm-10">
            <select class="form-control enrich-drop-down" data-form="ProductAttrKey_Id" value="{{ProductAttrKey_Id}}">
                <option value="">请选择类型</option>
                {{each keyvalue i}}
                <option value="{{i.Id}}" {{if i.Id==ProductAttrKey_Id}} selected {{/if}}>{{i.AttrName}} </option>
                {{/each}}
            </select>
           
        </div>
    </div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
            <button type="button" class="btn" onclick="window.history.go(-1)">返回</button>
        </div>
    </div>
</script>
<link href="/script/valid/css/tr.css" rel="stylesheet"/><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>
<script>
    $(function () {

        $.http.request("product/parameterdata", {},
            {
                pass: function (d) {
                    values(d.skuKeyList);
                }
            }
        );
   


    })

    function values(key) {
        var id = QueryPageUrlString("v");//判断是否是编辑进来的
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "AttrValue",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "ProductAttrKey_Id",
                    datatype: "n",
                    nullmsg: "不能为空哦",
                    errormsg: "请正确输入！"
                },
                {
                    key: "AttrName",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
            ];
            formValidEvent = $(".form-body").formValid(formValidData);
        }
        var inintData = {
            AttrValue: "",
            ProductAttrKey_Id: "",
            keyvalue: key
        };

        if (id > 0) { //存在值的情况
            $.http.json("pattrvalue/find", {   //查询
                Id: id
            }, {
                    pass: function (data) {
                        data.pageid = id;
                        data.keyvalue = key;
                        $("#form").templateRender({ el: "tp-form", data: data });//渲染模板，要先渲染才能获值
                        formValidInit();
                    },
                    error: function (d) {
                        console.log(d);
                    }
                })
        } else {
            $("#form").templateRender({ el: "tp-form", data: inintData });//渲染模板，要先渲染才能获值
            formValidInit();
        }

        $("#form").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!formValidEvent.check()) {
                return;
            }
            var apiUrl = "pattrvalue/insert";
            if (id > 0) {
                apiUrl = "pattrvalue/upd";
            }
            $("#form").ajaxFormSubmit(apiUrl, {
                pass: function (d) {
                    $.msgSucceed(d.Errmsg);
                    window.location.href = "list.html";
                    return
                },
                error: function (d) {
                    console.log(d)
                    $.msgFall(d.Errmsg);
                }
            }, { addData: { Id: id } })
            return
        });
    }
</script>
